package Services;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import javaBeans.LoginObject;

public class LoginService {

	public LoginObject confirmLogin(String username, String password) {
		DBConnection connection = new DBConnection();
		CallableStatement cs = null;
		ResultSet rs = null;
		Connection con = null;
		int logincode = 0;
		LoginObject loginDetails = new LoginObject();
		try {
			con = connection.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			cs = con.prepareCall("{call LOGINREQUEST(?,?)}");
			cs.setString(1, username);
			cs.setString(2, password);
			rs = cs.executeQuery();

			while (rs.next()) {
				String usernameMember = rs.getString("username");
				int idMember = rs.getInt("idmember");
				loginDetails.setIdmember(idMember);
				loginDetails.setUsername(usernameMember);
			}
			cs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(logincode);
		return loginDetails;
	}
}

/*
 * package Services;
 * 
 * import java.sql.CallableStatement; import java.sql.Connection; import
 * java.sql.ResultSet;
 * 
 * public class LoginService { DBConnection dbconnection = new DBConnection();
 * CallableStatement cs = null; Connection con = null; ResultSet rs = null; int
 * logincode;
 * 
 * public int addMemberRequest(String username, String password, String fname,
 * String lname, String email) { try { con = dbconnection.getConnection(); }
 * catch (Exception e) { e.printStackTrace(); }
 * 
 * try { cs = this.con.prepareCall("{call LOGINREQUEST(?,?)}"); cs.setString(1,
 * username); cs.setString(2, password); rs = cs.executeQuery();
 * 
 * while (rs.next()) { logincode = rs.getInt("logincode"); } cs.close(); } catch
 * (Exception e) { e.printStackTrace(); } System.out.println(logincode); return
 * logincode;
 */